From 5bee6e9c9fcee9c8fb592a19de84b0887bbb7ad2 Mon Sep 17 00:00:00 2001 From: tsteven4 Date: Fri, 2 Aug 2013 13:01:13 +0000 Subject: [PATCH] fix tpo memory leaks. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4499 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/tpo.cc | 82 ++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/gpsbabel/tpo.cc b/gpsbabel/tpo.cc index f9e0c799e..02b19279a 100644 --- a/gpsbabel/tpo.cc +++ b/gpsbabel/tpo.cc @@ -238,37 +238,6 @@ tpo_read_until_section(const char* section_name, int seek_bytes) } } -static void -tpo_rd_init(const char* fname) -{ - - tpo_file_in = gbfopen_le(fname, "rb", MYNAME); - tpo_check_version_string(); - - if (tpo_version == 2.0) { - if (doing_wpts || doing_rtes) { - fatal(MYNAME ": this file format only supports tracks, not waypoints or routes.\n"); - } - - /*fprintf(stderr,"Version 2.x, Looking for CTopoRoute\n"); */ - /* Back up 18 bytes if this section found */ - tpo_read_until_section("CTopoRoute", -18); - } else if (tpo_version == 3.0) { - /*fprintf(stderr,"Version 3.x, Looking for 'Red Without Arrow'\n"); */ - /* Go forward four more bytes if this section found. "IEND" - * plus four bytes is the end of the embedded PNG image */ - tpo_read_until_section("Red Without Arrow", 17); - } else { - fatal(MYNAME ": gpsbabel can only read TPO versions through 3.x.x\n"); - } -} - -static void -tpo_rd_deinit(void) -{ - gbfclose(tpo_file_in); -} - @@ -1067,6 +1036,7 @@ void tpo_process_map_notes(void) notes[name_length] = '\0'; // Terminator waypoint_temp->url = notes; //printf("Notes: %s\n", notes); + xfree(notes); } // Length of text for image path. If non-zero, skip past @@ -1082,6 +1052,7 @@ void tpo_process_map_notes(void) notes[name_length] = '\0'; // Terminator waypoint_temp->url = notes; //printf("Notes: %s\n", notes); + xfree(notes); } //UNKNOWN DATA LENGTH @@ -1358,14 +1329,6 @@ void tpo_process_routes(void) } //printf("\n"); } - - // Free the waypoint index, we don't need it anymore. - for (ii = 0; ii < tpo_index_ptr; ii++) { - waypt_free(tpo_wp_index[ii]); - } - - // Free the index array itself - xfree(tpo_wp_index); } @@ -1444,6 +1407,47 @@ void tpo_read_3_x(void) +static void +tpo_rd_init(const char* fname) +{ + + tpo_file_in = gbfopen_le(fname, "rb", MYNAME); + tpo_check_version_string(); + + if (tpo_version == 2.0) { + if (doing_wpts || doing_rtes) { + fatal(MYNAME ": this file format only supports tracks, not waypoints or routes.\n"); + } + + /*fprintf(stderr,"Version 2.x, Looking for CTopoRoute\n"); */ + /* Back up 18 bytes if this section found */ + tpo_read_until_section("CTopoRoute", -18); + } else if (tpo_version == 3.0) { + /*fprintf(stderr,"Version 3.x, Looking for 'Red Without Arrow'\n"); */ + /* Go forward four more bytes if this section found. "IEND" + * plus four bytes is the end of the embedded PNG image */ + tpo_read_until_section("Red Without Arrow", 17); + } else { + fatal(MYNAME ": gpsbabel can only read TPO versions through 3.x.x\n"); + } +} + +static void +tpo_rd_deinit(void) +{ + unsigned int i; + + // Free the waypoint index, we don't need it anymore. + for (i = 0; i < tpo_index_ptr; i++) { + waypt_free(tpo_wp_index[i]); + } + + // Free the index array itself + xfree(tpo_wp_index); + + gbfclose(tpo_file_in); +} + static void tpo_read(void) { -- 2.30.2